<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
            label-width="68px">
            <el-form-item label="工序编码" prop="code">
                <el-input v-model="queryParams.code" placeholder="请输入工序编码" clearable
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="工序名称" prop="name">
                <el-input v-model="queryParams.name" placeholder="请输入工序名称" clearable
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="图纸号" prop="shuoming">
                <el-input v-model="queryParams.shuoming" placeholder="请输入图纸号" clearable
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="产品编码" prop="goodsCode">
                <el-input v-model="queryParams.goodsCode" placeholder="请输入产品编码" clearable
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="生产产品名称" prop="goodsName">
                <el-input v-model="queryParams.goodsName" placeholder="请输入生产产品名称" clearable
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="生产产品型号" prop="goodsModel">
                <el-input v-model="queryParams.goodsModel" placeholder="请输入生产产品型号" clearable
                    @keyup.enter.native="handleQuery" />
            </el-form-item>

            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                    v-hasPermi="['develop:LnGongxu:add']">新增</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="multiple"
                    @click="handleUpdateAll" v-hasPermi="['develop:LnGongxu:edit']">修改图纸号</el-button>
            </el-col>
            <!--
            <el-col :span="1.5">
              <el-popconfirm title="确认删除选择的数据项？" @confirm="handleDelete({})">
                <el-button slot="reference" type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"
                           v-hasPermi="['develop:LnGongxu:remove']">删除</el-button>
              </el-popconfirm>
            </el-col>
            <el-col :span="1.5">
                <el-button type="warning" plain icon="el-icon-download" size="mini"
                        @click="handleExport" v-hasPermi="['develop:LnGongxu:export']">导出</el-button>
            </el-col>-->
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table border v-loading="loading" :data="dataList" @selection-change="handleSelectionChange" ref="table"
            :max-height="tableMaxHeight">
            <el-table-column type="selection" width="55" align="center" />
            <!-- <el-table-column label="${comment}" align="center" prop="id"/> -->
            <el-table-column label="工序编码" align="center" prop="code" />
            <el-table-column label="生产产品名称" align="center" prop="goodsName" />
            <el-table-column label="生产产品型号" align="center" prop="goodsModel" />
            <el-table-column label="工时" align="center" prop="workHour" />
            <el-table-column label="车间名称" align="center" prop="deptName" />
            <el-table-column label="工序名称" align="center" prop="name" />
            <el-table-column label="计件工资" align="center" prop="money" />
            <el-table-column label="关联设备" align="center" prop="photo" />
            <el-table-column label="图纸号" align="center" prop="shuoming" />
            <el-table-column align="center" label="工序文件" prop="file" width="200">
                <template slot-scope="scope">
                    <image-preview :src="scope.row.file" height="60px" width="40px"></image-preview>
                </template>
            </el-table-column>
            <!--<el-table-column align="center" label="工艺图纸" prop="photo" width="200">
              <template slot-scope="scope">
                <image-preview :src="scope.row.photo" height="60px" width="40px"></image-preview>
              </template>
            </el-table-column>-->
            <el-table-column label="备注" align="center" prop="remark" />
            <!--<el-table-column label="工序状态" align="center" prop="status"/>
            <el-table-column label="所属工艺" align="center" prop="haveGongyi"/>
            <el-table-column label="是否质检" align="center" prop="isZhijian"/>
                    <el-table-column label="准备时间" align="center" prop="readyDate" width="180">
                        <template slot-scope="scope">
                            <span>{{ parseTime(scope.row.readyDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="生产时间" align="center" prop="prodDate" width="180">
                        <template slot-scope="scope">
                            <span>{{ parseTime(scope.row.prodDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="生产结束时间" align="center" prop="endDate" width="180">
                        <template slot-scope="scope">
                            <span>{{ parseTime(scope.row.endDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="质检时间" align="center" prop="zhijianDate" width="180">
                        <template slot-scope="scope">
                            <span>{{ parseTime(scope.row.zhijianDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
                        </template>
                    </el-table-column>-->
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                        v-hasPermi="['develop:LnGongxu:edit']">修改</el-button>
                    <el-popconfirm :title="`确认删除当前数据项？`" @confirm="handleDelete(scope.row)" style="margin-left: 10px;">
                        <el-button slot="reference" size="mini" type="text" icon="el-icon-delete"
                            v-hasPermi="['develop:LnGongxu:remove']">删除</el-button>
                    </el-popconfirm>
                </template>
            </el-table-column>
        </el-table>

        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
            @pagination="getList" />

        <lnGongxu-form ref="form" @ok="getList"></lnGongxu-form>
        <lnGongxu-form-all ref="formAll" @ok="getList"></lnGongxu-form-all>
    </div>
</template>

<script>
import { deleteAction, getAction } from '@/api/manage'
import LnGongxuForm from '@/views/develop/lnGongxu/module/LnGongxuForm'
import LnGongxuFormAll from '@/views/develop/lnGongxu/module/LnGongxuFormAll'

export default {
    name: "LnGongxuList",
    components: {
        LnGongxuForm,
        LnGongxuFormAll,
    },
    data() {
        return {
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 工序表格数据
            dataList: [],
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                name: null,
                shuoming: null,
                file: null,
                photo: null,
                status: null,
                code: null,
                haveGongyi: null,
                isZhijian: null,
                readyDate: null,
                prodDate: null,
                endDate: null,
                zhijianDate: null,
                goodsCode: null,
                goodsName: null,
                goodsModel: null,
                /*orderByColumn: "code",
                isAsc: "asc",*/
            },
            url: {
                list: '/lnGongxu/lnGongxu/list',
                remove: '/lnGongxu/lnGongxu/',
                export: '/lnGongxu/lnGongxu/export',
            },
            tableMaxHeight: window.innerHeight - 320,
        };
    },
    created() {
        this.getList();
        window.addEventListener('resize', this.getTableHeight);
    },
    destroyed() {
        window.removeEventListener('resize', this.getTableHeight)
    },
    methods: {
        /** 查询工序列表 */
        getList() {
            this.loading = true;
            getAction(this.url.list, this.queryParams).then(response => {
                this.dataList = response.rows;
                this.total = response.total;
                this.loading = false;
            });
        },
        getTableHeight() {
            this.tableHeight = window.innerHeight - 320
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.id)
            this.single = selection.length !== 1
            this.multiple = !selection.length
        },
        /** 新增按钮操作 */
        handleAdd() {
            this.$refs.form.handleAdd();
        },
        /** 修改按钮操作 */
        handleUpdate(row) {
            this.$refs.form.handleUpdate(row);
        },
        handleUpdateAll() {
            const ids = this.ids;
            this.$refs.formAll.handleUpdate(ids);
        },
        /** 删除按钮操作 */
        handleDelete(row) {
            const ids = row.id || this.ids;
            deleteAction(this.url.remove, ids).then(response => {
                this.getList();
                this.$modal.msgSuccess("删除成功");
            }).catch(() => { });
        },
        /** 导出按钮操作 */
        handleExport() {
            this.download(this.url.export, {
                ...this.queryParams
            }, `lnGongxu_${new Date().getTime()}.xlsx`)
        },
    }
};
</script>
